<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{commons/commons::head}"/>
<head>
	<link rel="stylesheet" type="text/css" th:href="@{/css/index.css}" />
	<link rel="stylesheet" type="text/css" th:href="@{/css/reg.css}" />
</head>

	<body>
		<!--头部-->
		<header class="header">
			<img th:src="@{/images/index/stumalllogo.png}" alt="" />
			<span class="pull-right"><small>欢迎访问</small><b>电脑商城</b></span>
		</header>
		<!--主体-->
		<div class="container mycontent text-left">
			<!--透明层 -->
			<div class="regDiv">
				<p>新用户注册</p>
				<!--表单开始-->
				<form id="form-reg" class="form-horizontal" role="form">
					<!--用户名-->
					<div class="form-group">
						<label class="col-md-3 control-label">名字：</label>
						<div class="col-md-8">
							<input name="username" type="text" class="form-control" placeholder="请输入用户名">
						</div>
					</div>
					<!--密码-->
					<div class="form-group">
						<label class="col-md-3 control-label"> 密码：</label>
						<div class="col-md-8">
							<input id="pwd" name="password" type="text" class="form-control" placeholder="请输入密码">
						</div>
					</div>
					<!--确认密码-->
					<div class="form-group">
						<label class="col-md-3 control-label"> 确认密码：</label>
						<div class="col-md-8">
							<input id="pwd2"  type="text" class="form-control" placeholder="请再次输入密码">
						</div>
					</div>
					<!--提交按钮-->
					<div class="form-group">
						<label class="col-md-3 control-label"></label>
						<div class="col-md-8">
							<input id="btn-reg" class="btn btn-primary" type="button" value="立即注册" />
							<span class="pull-right"><small>已经有账号？</small><a th:href="@{/toLogin}">登录</a></span>
						</div>
					</div>
				</form>
			</div>
		</div>
	<div th:replace="~{commons/commons::footer}"/>
		<script type="text/javascript">
			$("#btn-reg").click(function() {
				console.log($("#form-reg").serialize());
				//对数据做校验
				if ($("#pwd").val() != $("#pwd2").val()){
					alert("密码不一致！")
					return;
				}
				$.ajax({
					url: "/user/addUser",
					type: "POST",
					data: $("#form-reg").serialize(),
					dataType: "json",
					success: function(data) {
						if (data.code == 200) {
							alert("注册成功！");
						} else {
							alert("注册失败！" + data.msg);
						}
					}
				});
			});
		</script>
	</body>

</html>